/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.service;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cmcc.zysoft.infocollection.dao.RolePcDao;
import com.cmcc.zysoft.infocollection.model.Role;
import com.starit.common.dao.hibernate.HibernateBaseDao;
import com.starit.common.dao.service.BaseServiceImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: RolePcService.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-6 上午9:43:49
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Service
public class RolePcService extends BaseServiceImpl<Role, String> {

	@Resource
	private RolePcDao rolePcDao;
	
	@Override
	public HibernateBaseDao<Role, String> getHibernateBaseDao() {
		return this.rolePcDao;
	}
	
	/**
	 * 获取角色分页列表信息.
	 * @param page
	 * @param rows
	 * @return map
	 */
	public Map<String, Object> roles(int page, int rows) {
		return this.rolePcDao.roles(page, rows);
	}
	
	/**
	 * 获取信息采集员的角色ID.
	 * @return List<Map<String, Object>>
	 */
	public String getCollectorRoleId() {
		List<Map<String, Object>> list = this.rolePcDao.getCollectorRoleId();
		if(null != list && !list.isEmpty()) {
			return list.get(0).get("role_id").toString();
		} else {
			return "";
		}
	}
	
	/**
	 * 添加角色.
	 * @param companyId 企业ID
	 * @return String(角色ID)
	 */
	@Transactional
	public String addRole(String companyId) {
		Role role = new Role();
		role.setCompanyId(companyId);
		role.setRoleName("信息采集员");
		role.setRoleCode("2");
		role.setDescription("信息采集员");
		role.setStatus("0");
		return this.rolePcDao.save(role);
	}
}